package edu.qichen.onlineBlog.comments.controller;

import edu.qichen.onlineBlog.comments.dto.*;
import edu.qichen.onlineBlog.comments.serivce.CommentsService;
import edu.qichen.onlineBlog.framework.AuthAccess;
import edu.qichen.onlineBlog.framework.DataResult;
import edu.qichen.onlineBlog.framework.OperationAnnotation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能:
 * 作者:程序员欧阳子韩
 * 日期:2024/5/2 17:51
 */
@RestController
@RequestMapping("/comments")
@Tag(name = "评论接口")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    /**
     * 查询评论信息
     *
     * @param pageLikesReq -
     * @return -
     */
    @Operation(summary = "查询评论信息")
    @AuthAccess
    @PostMapping("/queryComments")
    public DataResult<PageCommentsRes<CommentsBlogsUserPageDto>> queryLikes(@RequestBody PageCommentsReq pageLikesReq) {
        return DataResult.success(commentsService.queryLikes(pageLikesReq));
    }

    /**
     * 左连接查询用户表和评论表
     *
     * @param pageUserCommentsReq -
     * @return -
     */
    @Operation(summary = "连接查询用户表和评论表")
    @PostMapping("/queryUserComments")
    public DataResult<PageCommentsRes<CommentsBlogsUserPageDto>> queryUserLikes(@RequestBody PageUserCommentsReq pageUserCommentsReq) {
        return DataResult.success(commentsService.queryUserLikes(pageUserCommentsReq));
    }

    /**
     * 添加评论
     *
     * @param addCommentReq -
     * @return -
     */
    @Operation(summary = "添加评论")
    @AuthAccess
    @PostMapping("/addComment")
    @OperationAnnotation(content = "用户和游客添加评论", sysType = 0, opType = 1, action = "成功")
    public DataResult<Boolean> addComment(@RequestBody AddCommentReq addCommentReq, HttpServletRequest request) {
        return DataResult.success(commentsService.addComment(addCommentReq,request));
    }

    /**
     * 删除评论信息
     *
     * @param id -
     * @return -
     */
    @Operation(summary = "删除评论信息")
    @DeleteMapping("/deleteById")
    @OperationAnnotation(content = "删除评论信息", sysType = 0, opType = 2, action = "成功")
    public DataResult<Boolean> deleteById(Integer id,HttpServletRequest request) {
        return DataResult.success(commentsService.deleteById(id,request));
    }
}
